package utildate;

import java.util.Calendar;
import java.util.Date;

public class CalendarDemo1 {
    public static void main(String[] args) {
        Calendar instance = Calendar.getInstance();
    }
    public static void main4(String[] args) {
        // 将date设置为Calendar对象
        Calendar calendar = Calendar.getInstance();

        calendar.set(Calendar.YEAR, 2000);
        System.out.println("calendar = " + calendar);

        // 月份增加2
        calendar.add(Calendar.MONTH, 3);
        System.out.println("calendar = " + calendar);
    }
    public static void main3(String[] args) {
        Date date = new Date(60*60*1000L);

        // 将date设置为Calendar对象
        Calendar calendar = Calendar.getInstance();
        // calendar.setTime(date);
        System.out.println("calendar = " + calendar);

        // 分别获取年、月、日、时、分、秒的值
        int year = calendar.get(Calendar.YEAR);
        System.out.println("year = " + year);//year = 1970

        int month = calendar.get(Calendar.MONTH);
        System.out.println("month = " + month); // month = 0     西方国家的月份表示: [0,11]   0代表一月 , 1代表二月 .... 11代表十二月

        int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
        System.out.println("dayOfMonth = " + dayOfMonth); // dayOfMonth = 1

        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
        System.out.println("dayOfWeek = " + dayOfWeek); //  dayOfWeek = 4   西方国家的星期数的值： [1,7]   1代表星期天 , 2代表星期一 .... 7代表星期六

        int hour = calendar.get(Calendar.HOUR);
        System.out.println("hour = " + hour); // hour = 9

        int minute = calendar.get(Calendar.MINUTE);
        System.out.println("minute = " + minute);  // minute = 0

        int second = calendar.get(Calendar.SECOND);
        System.out.println("second = " + second); // second = 0

        int millisecond = calendar.get(Calendar.MILLISECOND);
        System.out.println("millisecond = " + millisecond); // millisecond = 0

    }
    public static void main2(String[] args) {
        Date date = new Date(0L);

        // 创建日历对象
        Calendar calendar = Calendar.getInstance();  // 获取当前计算机显示日期时间对象的日历
        System.out.println("calendar = " + calendar);

        calendar.setTime(date);
        System.out.println("calendar = " + calendar);

        Date time = calendar.getTime();
    }
    public static void main1(String[] args) {
        Date date = new Date();
        System.out.println("date = " + date); // date = Wed Oct 22 15:31:18 CST 2025
        // 灵活的增加或者减少： 年份值 , 月份值 , 日期值 , 时分秒值
    }
}
